export default {
  namespaced: true, //开启命名空间
  state: () => ({
    address: JSON.parse(uni.getStorageSync('address') || '{}') //收货地址
  }),
  mutations: {
    //更新收货地址
    updateAddress(state, address) {
      state.address = address
      this.commit('m_user/saveAddressToStorage')
    },

    //保存地址信息到本地
    saveAddressToStorage(state) {
      uni.setStorageSync('address', JSON.stringify(state.address))
    },
  },
  getters: {
    addstr(state) { //详细收货地址的计算属性
      if (!state.address.provinceName) return ''
      //拼接省,市,区,详细地址等信息
      return state.address.provinceName + state.address.cityName + state.address.countyName + state.address.detailInfo
    }
  }
}
